﻿using Autofac;

namespace AppFx.BizTalk.Container
{
    public class ApplicationContainer
    {
        private readonly ContainerBuilder _containerBuilder;
        private IContainer _container;

        public ApplicationContainer()
        {
            _containerBuilder = new ContainerBuilder();
        }        

        public void LoadContainer(string[] assemblies)
        {
            _containerBuilder.InstallFromAssemblies(assemblies);            
        }

        public void BuildContainer()
        {            
            _container = _containerBuilder.Build();
        }

        public void LoadFrom(Loaders.IContainerLoader containerLoader, string loaderKey)
        {
            containerLoader.Load(_containerBuilder, loaderKey);
        }

        public void ClearContainer()
        {
            _container = null;
        }

        public IContainer Container
        {
            get { return _container; }
        }

        public ContainerBuilder ContainerBuilder
        {
            get { return _containerBuilder; }
        }
    }
}
